<?php
#########################################
# Socket Library
# Simple library for handling socket
# connections.
# Created by 1337D00D
#########################################


class Socket
{
	public $Socket;
	
	public function Read($length = 2048)
	{
		if(!$read=fread($this->Socket,$length))
		{
			//trigger_error("Warning : Socket->Read() could not read socket. Additional details: $errstr ($errno)",E_USER_WARNING);
			return false;
		}
		return $read;
	}
	
	public function Write($buffer,$read=false)
	{
		if(!fwrite($this->Socket,$buffer))
		{
			//trigger_error("Warning : Socket->Write() could not write to socket. Additional details: $errstr ($errno)",E_USER_WARNING);
			return false;
		}
		if($read)
		{
			return $this->Read();
		}
		return true;
	}
	
	public function __construct($host = "localhost", $port = 8092)
	{
		if(!$sock = @fsockopen($host,$port,$errno,$errstr,10))
		{
			trigger_error("Warning : Socket->__construct() could not connect to host '$host:$port'. Additional details: $errstr ($errno)",E_USER_WARNING);
			return false;
		}
		$this->Socket = $sock;
	}
	
	public function __destruct()
	{
		fclose($this->Socket);
	}
}

?>